package com.vecspace.dayu.code.template.pojo;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dicttable.CodeItem;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** 页面布局类型
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_TEMPLATE_PAGE_LAYOUT")
public class TemplatePageLayout implements IdEntity, java.io.Serializable {
	
	private static final long serialVersionUID = 2052086021655230969L;
	public TemplatePageLayout(){
	}

	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}
	
	private String terminalType;//
	public static final String TerminalTypeCode = "DAYU-CODE-006";//

	/**终端类型  WEB APP PAD*/
	@Column(name = "TERMINAL_TYPE")
	public String getTerminalType() {
		return terminalType;
	}
	/**终端类型  WEB APP PAD*/
	public void setTerminalType(String terminalType) {
		this.terminalType = terminalType;
	}
	@Transient
	public String getTerminalTypeCaptioin() {
		return DictAll.getItemName(TerminalTypeCode, terminalType);
	}
	
	private String layoutName;
	/**页面布局名称*/
	@Column(name = "LAYOUT_NAME")
	public String getLayoutName(){
		return layoutName;
	}
	/**页面布局名称*/
	public void setLayoutName(String value){
		this.layoutName = value;
	}

	private String tablesRelation;
	/** 1单表，2目录+叶子表，3主表+从表  TablesRelation*/
	@Column(name = "TABLES_RELATION")
	public String getTablesRelation() {
		return tablesRelation;
	}
	/** 1单表，2目录+叶子表，3主表+从表 TablesRelation */
	public void setTablesRelation(String tablesRelation) {
		this.tablesRelation = tablesRelation;
	}
	private static String TablesRelationCode="DAYU-CODE-003";
	@Transient
	public String getTablesRelationCaption() {
		return DictAll.getCachedItemName(TablesRelationCode, tablesRelation);
	}
	@Transient
	public List<CodeItem> getTablesRelations(){
		return DictAll.getItems(TablesRelationCode);
	}

	private String imgPath;
	/**缩略图路径*/
	@Column(name = "IMG_PATH")
	public String getImgPath(){
		return imgPath;
	}
	/**缩略图路径*/
	public void setImgPath(String value){
		this.imgPath = value;
	}
	
	private Integer status;
	@Column(name = "STATUS_")
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	private String storageType;
	@Column(name = "STORAGE_TYPE")
	public String getStorageType() {
		return storageType;
	}
	public void setStorageType(String storageType) {
		this.storageType = storageType;
	}

	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.terminalType = rowMapper.getString("TERMINAL_TYPE");
		this.layoutName = rowMapper.getString("LAYOUT_NAME");
		this.tablesRelation = rowMapper.getString("TABLES_RELATION");
		this.imgPath = rowMapper.getString("IMG_PATH");
		this.status = rowMapper.getInteger("STATUS_");
		this.storageType = rowMapper.getString("STORAGE_TYPE");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		TemplatePageLayout other = (TemplatePageLayout)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
